package com.hsurosy.hsuchain.nft.user.infrastructure;

import com.hsurosy.hsuchain.nft.api.chain.service.ChainFacadeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * UserDubboConfiguration 配置类
 *
 * @Author Hsu琛君珩
 * @Date 2024-10-05 18:24
 * @Description
 * @Version: v1.0.0
 */
@Configuration
public class UserDubboConfiguration {

    /**
     * 通过 Dubbo 引入 ChainFacadeService 服务
     *
     * @DubboReference 注解标注的字段表示通过 Dubbo 服务调用的方式获取 ChainFacadeService。
     * 该服务的版本号为 1.0.0。
     */
    @DubboReference(version = "1.0.0")
    private ChainFacadeService chainFacadeService;

    /**
     * 注册 ChainFacadeService Bean
     *
     * @ConditionalOnMissingBean 注解确保当 Spring 容器中不存在同名的 Bean 时，才创建并注册该 Bean。
     *
     * @return ChainFacadeService 实例
     */
    @Bean
    @ConditionalOnMissingBean(name = "chainFacadeService")
    public ChainFacadeService chainFacadeService() {
        return chainFacadeService;
    }
}
